/**个人动态发表*/
function ajaxfabiao(){
	$.ajax({
	type:'POST',
	url:'user/article/comment',
	data:{'articleId':'${article.id}','commentContent':$(".pinglun-content").html()},
	dataType:'json',
	 success:function(data){
				if(data && data.success){
						alert(data.message);
						$(".pinglun-list").prepend("<li><div class=\"pinglun-date\">xx评论时间:&nbsp;&nbsp;"+formatDate(data.object.commentDate)+"</div><div class=\"pinglun-comment\">"+data.object.commentContent+"</div></li>");
				}else{
					alert(data.message);
				}},
				error:function(data){
					alert(data.message);
				} 
});
}

/**个人未读消息总数*/
function getMsgTotal(){
	$.ajax({
	type:'POST',
	url:'user/notifications/notReadMsgTotal',
	data:{},
	dataType:'json',
	 success:function(data){
				if(data && data.success){
					$("#total").html(data.object);
				}else{
				}},
});
}

setInterval("getMsgTotal()",1000*60*10);


/*验证码*/
function changeImg(){
	var code=document.getElementById("code");
  	code.src="servlet/ServletCode?"+new Date();
}

function register2(url,type){
	alert(type);
}

function registerCheck(type){
	var username = $("#username").val();
	var password = $("#password").val();
	if(!(/^\w{5,15}$/.test(username))){
	  	$("#span1").html("用户名必须是5~15位!");
	  	$("#span1").css("color","red");
	  	return false;
	  }else{
		  $("#span1").html("");
	  }
	
	 if(!(/^\w{6,12}$/.test(password))){
		$("#span3").html("密码必须是6~12位!");
		$("#span3").css("color","red");
	  	return false;
	  	}else{
	  		 $("#span3").html("");
	  	}
}

/*注册验证*/
function register(type){
		$.ajax({
			type:'POST',
			url:'user/register?type='+type,
			data:$('#register').serialize(),//将表单序列化字符串
			dataType:'json',
			success:function(data){
				if(data && data.success){
					if(data.code == 1){//帐号可以使用
						$("#span1").html(data.message);
						$("#span1").css("color","green");
					}else if(data.code == 2){//邮箱可以使用
						$("#span2").html(data.message);
						$("#span2").css("color","green");
					}else if(data.code == 0){
						alert(data.message);
					}
				}else{
					if(data.code == -1){//帐号已被注册
						$("#span1").html(data.message);
						$("#span1").css("color","red");
					}else if(data.code == -2){//邮箱已存在
						$("#span2").html(data.message);
						$("#span2").css("color","red");
					}else if(data.code == -3){
						alert(data.message);
					}
				}}
		});
}

	
function checkUser(url){
	var username = $("#username").val();
	var password = $("#password").val();
	if(username == "" || password == ""){
		alert("用户名或者密码不能为空!");
		return false;
	}else{
		ajaxLogin(url);
	}
}

function ajaxLogin(url){
	$("#login-button").val("登陆中,请稍等...");
	$.ajax({
		type:'POST',
		url:'user/login',
		data:$('#form-login').serialize(),//将表单序列化字符串
		dataType:'json',
		success:function(data){
			if(data && data.success){
				window.location.href=url+'index';
			}else{
				if(data.code == -3){
					$("#span1").html(data.message);
					$("#span2").html("");
				}else if(data.code == -2){
					$("#span1").html("");
					$("#span2").html(data.message);
				}
					$("#login-button").val("登陆");	
			}},
	});
}

/*消息页面*/
$(function(){
	$('.notifications a').click(function(){
		var index = $(this).index();
		//alert(index);
		$(this).addClass('notifications-activate').siblings().removeClass('notifications-activate');
	});
});

/**
 * 修改密码
 */
function updatePwd(){debugger
	if($('#password').val() == '' || $('#password').val().length<6 || $('#password').val().length>12 || $('#confrmPassword').val() == ''){
		showAlertDiv("密码或确认密码不能为空，且长度必须在6~12位!");
	}else if(!/^\w{6,12}$/.test($('#password').val())){
		showAlertDiv("密码必须由字母,数字或者下划线组成!");
	}else if($('#password').val() !=$('#confrmPassword').val() ){
		showAlertDiv("两次输入的密码不一致!");
	}else{
		$('#pwd').val($.md5($('#password').val()+$('#username').val()));
		$('#pwdForm').submit();
	}
}

/**
 * 发表动态
 */
function publicMoment(){
	var publicContent = $('#publicContent').html();
	if(publicContent == '' || publicContent.length >25){
		return;
	}
	$.ajax({
	type:'POST',
	url:'user/moments/publicMoment',
	data:{'content':publicContent},
	dataType:'json',
	 success:function(data){
				if(data && data.success){
					var cLi ="<li><div class=\"list-date\">时间:"+formatDate(new Date())+"</div><div class=\"list-content\">"+data.object.content+"</div><div class=\"list-comment\">评论(<span style=\"color: red;\">0</span>)|赞(<span style=\"color: red;\">0</span>)</div></li>";
					$(".per-ss-list ul").prepend(cLi);
					$('#publicContent').html('');
				}else{
					showAlertDiv(data.message);
				}
		}
});
}
